package dataStructures;

import exceptions.InvalidDataException;

public class Location {
	public String latitude;
	public String longitude;
	public String radius;
	public String unit;
	
	public Location () {
		
	}
	
	public Location(String latitude, String longitude) throws InvalidDataException {
		this.latitude = latitude;
		this.longitude = longitude;
	}
	
	public Location(String latitude, String longitude, String radius, String unit) throws InvalidDataException {
		this.latitude = latitude;
		this.longitude = longitude;
		this.radius = radius;
		this.unit = unit;
	}

	private void printValues(String[] values) {
		for (int i=0; i<values.length; i++) {
			System.out.println(values[i]);
		}
	}
	
	public Location(String geoCode) {
		try {
			//50.0,10.0,1000.0km
			String[] values = geoCode.split(",");
			printValues(values);
			this.latitude = values[0];
			this.longitude = values[1];
			this.radius = values[2].substring(0, values[2].length() - 2);
			this.unit = values[2].substring(values[2].length() - 2).equalsIgnoreCase("km") ? "kilometers" : "miles";
		} catch (NullPointerException e) {
			
		}
	}

	public String toString() {
		return "lat:" + latitude + " lon:" + longitude + " rad:" + radius + " unit:" + unit;
	}
}
